home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-03 | 1.8 KB | 94 lines | [TEXT/MMCC] |
-
- // * Comment Tzu
- // * ©1994 Michael A. Kelly. All Rights Reserved.
- // *
- // * 100 11 Oct 94 ckt
- // * 101 13 Oct 94 ckt - rewrote to comment more intelligently
- // * & wrote InsertText & comment
- // * 102 27 Oct 94 mak - rewrote to comment more intelligently
- // * and to comment and uncomment with the same command, ala CMaster
-
- #include "TzuTools.h"
-
-
-
- pascal void main(
- Handle text );
-
-
-
- pascal void main(
- Handle text )
- {
-
- EnterCodeResource();
-
- long size;
-
- HUnlock( text );
-
- if ( (*text)[0] == '/' && (*text)[1] == '/' ) {
-
- const char *commentText = "\r";
- Str15 findText = "\p\r//";
- Handle commentStr = NewHandleClear( 1 );
-
- BlockMoveData( commentText, *commentStr, 1 );
-
- size = GetHandleSize( text );
- BlockMove( *text + 2, *text, size - 2 );
- SetHandleSize( text, size - 2 );
-
- if ( ReplaceText( text, commentStr, findText ) < 0 ) {
- SysBeep(0);
- }
-
- DisposeHandle( commentStr );
-
- } else {
-
- const char *commentText = "\r//";
- Str15 findText = "\p\r";
- Handle commentStr = NewHandleClear( 3 );
- Boolean endReturn;
-
- BlockMoveData( commentText, *commentStr, 3 );
-
- size = GetHandleSize( text );
- SetHandleSize( text, size + 2 );
- if ( MemError() ) {
- SysBeep(0);
- DisposeHandle( commentStr );
- goto ret;
- }
- BlockMove( *text, *text + 2, size );
- (*text)[0] = (*text)[1] = '/';
- if ( (*text)[size + 1] == '\r' ) {
- SetHandleSize( text, size + 1 );
- endReturn = (MemError() == noErr);
- } else {
- endReturn = false;
- }
- if ( ReplaceText( text, commentStr, findText ) < 0 ) {
- SysBeep(0);
- }
- if ( endReturn ) {
- size = GetHandleSize( text );
- SetHandleSize( text, size + 1 );
- if ( MemError() == noErr ) {
- (*text)[size] = '\r';
- }
- }
-
- DisposeHandle( commentStr );
-
- }
-
-
- ret:
-
- HLockHi( text );
-
- ExitCodeResource();
-
- }